package org.jradweb.tools.generator.untils;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import freemarker.cache.TemplateLoader;
/**
 * 
 * for load db script
 * @author paul
 *
 */
public class DBScriptTemplateLoader implements TemplateLoader {
	public Map<String,String> statements=new HashMap<String,String>();
	private int id=0;
	
	public String putStatement(String statement){
		String name="statement"+id;
		id++;
		statements.put(name, statement);
		return name;
	}	
	public void closeTemplateSource(Object templateSource) throws IOException {
		// TODO Auto-generated method stub

	}

	public Object findTemplateSource(String name) throws IOException {
		return statements.get(name);
	}

	public long getLastModified(Object templateSource) {
		return -1;
	}

	public Reader getReader(Object templateSource, String encoding)
			throws IOException {
		//InputStream is=new FileInputStream((String)templateSource);	
		java.io.StringReader reader=new StringReader(templateSource.toString());
		return reader;
	}

}
